package qrcode;

public enum DataMaskPattern {
  NO_MASK((byte)0),
  MASK_0((byte)0),
  MASK_1((byte)1),
  MASK_2((byte)2),
  MASK_3((byte)3),
  MASK_4((byte)4),
  MASK_5((byte)5),
  MASK_6((byte)6),
  MASK_7((byte)7);

  private byte binaryIndicator;

  private DataMaskPattern(byte binaryIndicator){
    this.binaryIndicator = binaryIndicator;
  }
  
  public byte getBinaryIndicator() {
    return binaryIndicator;
  }
  
  /**
   * 
   * @param j column
   * @param i row
   * @return
   */
  public boolean mask(final int j, final int i, boolean value){
    return isMasked(j, i)?!value:value;
  }
  
  public boolean isMasked(final int j, final int i){
    switch (this){
    case NO_MASK:
      return false;
    case MASK_0:
      return (i+j)%2 == 0;
    case MASK_1:
      return i %2 == 0;
    case MASK_2:
      return j % 3 == 0;
    case MASK_3:
      return (i+j)%3 == 0;
    case MASK_4:
      return ((i/2) + (j/3) ) % 2 == 0;
    case MASK_5:
      return ((i*j) % 2) + ((i*j) % 3) == 0;
    case MASK_6:
      return ((i*j) % 2) + ((i*j) % 3) %2 == 0;
    case MASK_7:
      return ((i+j) % 2) + ((i*j) % 3) %2 == 0;
    }
    throw new IllegalStateException("Mask " + this + " ist not yet implemented.");
  }
}